#include <stdio.h>

int main() {
    int N;
    int arr[10];

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }

    int minIndex = 0;
    for (int i = 1; i < N; i++) {
        if (arr[i] < arr[minIndex]) {
            minIndex = i;
        }
    }

    if (minIndex != 0) {
        int temp = arr[0];
        arr[0] = arr[minIndex];
        arr[minIndex] = temp;
    }

    int maxIndex = 0;
    for (int i = 1; i < N; i++) {
        if (arr[i] > arr[maxIndex]) {
            maxIndex = i;
        }
    }

    if (maxIndex != N - 1) {
        int temp = arr[N - 1];
        arr[N - 1] = arr[maxIndex];
        arr[maxIndex] = temp;
    }

    for (int i = 0; i < N; i++) {
        printf("%d ", arr[i]);
    }

    return 0;
}
